package com.yuri.news.jpa;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import com.yuri.news.entity.Depa;

/**
 * 部门jpa
 * @author Yuri
 */
public interface DepaRepository extends JpaRepository<Depa, Long>, JpaSpecificationExecutor<Depa> {
	/**
	 * 根据部门Id查询部门下的所有部门
	 * @param id
	 * @return
	 */
	@Query(value = "SELECT * FROM t_depa t1 INNER JOIN t_depa t2 ON t1.up_depa_id = t2.id where t2.id = ?1",nativeQuery = true)
	List<Depa> findDepaAll(Long id);
	
	/**
	 * 根据部门Id查询部门下的所有部门(分页)
	 * @param id
	 * @return
	 */
	@Query(value = "SELECT * FROM t_depa t1 INNER JOIN t_depa t2 ON t1.up_depa_id = t2.id where t2.id = ?1",
			countQuery =  "SELECT count(*) FROM t_depa t1 INNER JOIN t_depa t2 ON t1.up_depa_id = t2.id where t2.id = ?1",
			nativeQuery = true)
	Page<Depa> findDepaAll(Long id, Pageable page);
	
	/**
	 * 根据部门名进行模糊查询
	 * @param depaName	部门名称(要带%)
	 * @return
	 */
	List<Depa> findByDepaNameLike(String depaName);
	
	/**
	 * 根据部门名进行模糊查询(分页查询)
	 * @param depaName		部门名称(要带%)
	 * @param page			分页信息
	 * @return
	 */
	Page<Depa> findByDepaNameLike(String depaName, Pageable page);
}
